﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace DAO
{
    public class ChiTietDonHangDAO
    {
        //Load Danh Sách Chi tiết đơn hàng theo mã đơn hàng
        public static DataTable LoadDanhSachChiTietTheoMaDH(string madh)
        {
            try
            {
                string sql = "select MaDH, MaCTDH, TenSP, SoLuong, DonGia from ChiTietDonHang c, SanPham s where c.MaSP = s.MaSP and MaDH = " + madh;
                return Dataprovider.ExcuteQuery(sql);
            }
            catch
            {
                return null;
            }
        }
        //Lay Don Hang Cuoi
        public static int DonHangCuoi()
        {
            DataService dservice = new DataService();
            dservice.Connect();
            DataTable dt = dservice.ExcuteQueryDataTable("Select Top 1 MaDH From DonHang Order by MaDH");
            dservice.Disconnect();
            return Int32.Parse(dt.Rows[0]["MaDH"].ToString());
        }
        //Them Don hang
        public static int ThemChiTietDonHang(String maSP, String Sl,String DonGia,String maDH)
        {
            try
            {
                string sql = "Insert into ChiTietDonHang Values("+maSP+","+Sl+","+DonGia+","+maDH+")";
                return Dataprovider.ExcuteNonQuery(sql);
            }
            catch
            {
                return 0;
            }
        }
    }
}
